import 'package:play_android/com/zhihaoliang/const/AppApi.dart';
import 'package:play_android/com/zhihaoliang/http/HttpException.dart';
import 'package:play_android/com/zhihaoliang/base/BaseRepository.dart';
import 'package:play_android/com/zhihaoliang/http/ResultData.dart';
import 'package:play_android/com/zhihaoliang/http/HttpRequest.dart';
import 'package:play_android/com/zhihaoliang/play/find/model/TreeClass.dart';
import 'package:play_android/com/zhihaoliang/play/find/model/TreeModel.dart';

///  ***************************************************************************
///  "知识体系的数据"请求处理
///  ***************************************************************************

class TreePresenter extends BaseRepository<List<TreeClass>> {
  TreeCallBack _callBack;

  TreePresenter(this._callBack);

  load() {
    fetch()
        .then((data) => _callBack.onLoadTreeComplete(data))
        .catchError((onError) => _callBack.onLoadTreeError(onError));
  }

  @override
  List<TreeClass> fetchModel(Map<String, dynamic> map) {
    TreeModel treeModel = TreeModel.fromJson(map);
    return treeModel.data;
  }

  @override
  Future<ResultData> fetchResultData(
      [String url, Map<String, dynamic> map]) async {
    return await HttpRequest().get(AppApi.TREE);
  }
}

abstract class TreeCallBack {
  void onLoadTreeComplete(List<TreeClass> list);

  void onLoadTreeError(HttpException httpException);
}
